package com.lottery.ruok.lottrey.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.ChooseLotteryActivity;
import com.lottery.ruok.lottrey.retrofitModule.response.LotteryStatOneResponse;

import java.util.ArrayList;

import ui.NoScrollGridView;

/**
 * Created by ASUS on 2017/11/13.
 */

public class ChooseLotteryListAdapter extends BaseAdapter {
    private ChooseLotteryActivity chooseLotteryActivity;
    private ArrayList<LotteryStatOneResponse.ItemListBean> item_lists;
    public ChooseLotteryListAdapter(ChooseLotteryActivity chooseLotteryActivity, ArrayList<LotteryStatOneResponse.ItemListBean> item_lists) {
        super();
        this.chooseLotteryActivity = chooseLotteryActivity;
        this.item_lists = item_lists;
    }

    @Override
    public int getCount() {
        return item_lists.size();
    }

    @Override
    public Object getItem(int position) {
        return item_lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(chooseLotteryActivity).inflate(R.layout.choose_type_item, null, false);
            holder.gridView = convertView.findViewById(R.id.grid_item);
            holder.name = convertView.findViewById(R.id.name);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.name.setText(item_lists.get(position).getNameX());
        if (holder.gridView != null) {
            ChooseLotteryGridAdapter gridViewAdapter = new ChooseLotteryGridAdapter(item_lists.get(position).getItems(), chooseLotteryActivity, chooseLotteryActivity);
            holder.gridView.setAdapter(gridViewAdapter);
        }

        return convertView;
    }

    static class ViewHolder {
        NoScrollGridView gridView;
        TextView name;
    }
}